home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12906 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: fast find algorithm
  5. Date: 3 Apr 1996 14:13:49 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4ju12t$ovh@news.xs4all.nl>
  8. References: <Dp8wE6.8DG@cix.compulink.co.uk>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. setheridge@cix.compulink.co.uk ("Stephen Etheridge") writes:
  13.  
  14. >Hi
  15.  
  16. >Does anyone have an search algoritm faster than a binary chop for the 
  17. >following:
  18.  
  19. >find a date from a sorted array of 1500 possible storage locations
  20.  
  21. It is theoretically not possible to find an entry in a sorted list
  22. in less than ceil(2log(N)) (=11 in this case) operations.  bsearch()
  23. does just that, so if it isn't fast enough you should try other methods.
  24.  
  25. A plain table lookup is fastest, but can only be done if the number
  26. of elements isn't too great -- would not work for dates unless you
  27. aren't interested in the year part, or if you have tons of memory
  28. (need 31*12*100 elements if you ignore the century).
  29.  
  30. Hashing is slightly slower than straight table lookup and can't be
  31. used when you want to delete elements from your table.
  32.  
  33. If you want to minimize time to *successfully* searching elements,
  34. and a few elements account for>90% of your input, you can sort the
  35. array into order of searches and use a linear search.
  36.  
  37. Frank
  38. --
  39. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  40. ------------------------------------------------------------------------
  41. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  42.